package com.panghl.controller;

import com.panghl.domain.ResponseResult;
import com.panghl.domain.User;
import com.panghl.service.LoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author panghl
 * @Date 2022/2/12
 * @Description 自定义登录接口
 **/
@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    /**
     * 也可以通过JWTLoginFilter extends UsernamePasswordAuthenticationFilter
     * attemptAuthentication方法进行尝试身份认证
     * 认证成功后回调 successfulAuthentication 方法  进行认证成功后的操作 eg:生成token
     * @param user
     * @return
     */
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user){
        //登录
        return loginService.login(user);
    }

    /**
     * 可以用过注销处理器 SGLogoutSuccessHandler 处理
     * @return
     */
    @RequestMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }




}
